package com.sprouting.ops.controller;

import com.sprouting.ops.model.OpsThirdPartySiteUser;
import com.sprouting.ops.model.ResultJson;
import com.sprouting.ops.model.qo.OpsThirdPartySiteUserQo;
import com.sprouting.ops.service.OpsThirdPartySiteUserService;
import com.sprouting.ops.utils.CheckTool;
import com.sprouting.ops.utils.EntityTool;
import com.sprouting.ops.utils.IdTool;
import org.springframework.web.bind.annotation.*;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sprouting.ops.annotations.invoke.IdempotentSingle;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import com.sprouting.ops.interfaces.AddGroup;
import com.sprouting.ops.interfaces.UpdGroup;

/**
 * 厂商现场人员表(OpsThirdPartySiteUser)(OPS_THIRD_PARTY_SITE_USER) 表控制层
 *
 * @author ：lx（长沙麓谷）
 * @date 创建时间：2025-08-03 10:28:50
 */
@Slf4j
@RestController
@RequestMapping("opsThirdPartySiteUser")
public class OpsThirdPartySiteUserController {

    @Resource
    private OpsThirdPartySiteUserService opsThirdPartySiteUserService;




    /**
     * 分页查询厂商现场人员表
     * @param query 查询参数
     * @return
     */
    @PostMapping("getListPage")
    public ResultJson getListPage(OpsThirdPartySiteUserQo query){
        Page page = query.getPage();
        return ResultJson.success(opsThirdPartySiteUserService.getListPage(page, query));
    }

    /**
     * 删除厂商现场人员表
     * @param id 厂商现场人员表id
     * @return
     */
    @PostMapping("delOpsThirdPartySiteUser")
    @IdempotentSingle
    public ResultJson delOpsThirdPartySiteUser(String id){
        if (CheckTool.checkNull(id)){
            return ResultJson.errorCheck();
        }

        opsThirdPartySiteUserService.removeById(id);
        return ResultJson.success();
    }

    /**
     * 更新厂商现场人员表
     * @param bo 修改参数
     * @return
     */
    @PostMapping("updOpsThirdPartySiteUser")
    @IdempotentSingle
    public ResultJson updOpsThirdPartySiteUser(@Validated(UpdGroup.class) OpsThirdPartySiteUser bo){
        String msg = checkOpsThirdPartySiteUser(bo);
        if (msg != null){
            return ResultJson.error(msg);
        }

        EntityTool.updBase(bo);
        opsThirdPartySiteUserService.updateById(bo);
        return ResultJson.success(bo);
    }

    /**
     * 保存厂商现场人员表
     * @param bo 保存参数
     * @return
     */
    @PostMapping("saveOpsThirdPartySiteUser")
    @IdempotentSingle
    public ResultJson saveOpsThirdPartySiteUser(@Validated(AddGroup.class) OpsThirdPartySiteUser bo){
        String msg = checkOpsThirdPartySiteUser(bo);
        if (msg != null){
            return ResultJson.error(msg);
        }

        bo.setId(IdTool.getId());
        EntityTool.saveBase(bo);
        opsThirdPartySiteUserService.save(bo);
        return ResultJson.success(bo);
    }


    /**
     * 厂商现场人员表数据校验
     * @param bo 厂商现场人员表 校验数据
     * @return 非null则有错误
     */
    private String checkOpsThirdPartySiteUser(OpsThirdPartySiteUser bo){

        return null;
    }

}
